package com.xx.secret.demo;

import com.alibaba.fastjson.JSONObject;
import com.xx.secret.entity.Result;
import com.xx.secret.enums.OpenEnum;
import com.xx.secret.notify.INotifyProcessor;
import com.xx.secret.notify.NotifyResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @author ：wangcheng
 * @date 2024/3/14
 * 三方回调处理类demo 项目实现NotifyProcessor
 * 本demo路径 localhost:8080/three/notify/xx/order
 * 路径访问 /three/notify/{apiName}/注册路径
 * demo参数 {"data":"jaG1JJ4C8zBVBeLPIMDLzw9ptF3jyeRyzC1kH0Vimqg="}
 **/
@Service
@Slf4j
public class DemoINotifyService implements INotifyProcessor {
    @Override
    public OpenEnum getApiLoan() {
        return OpenEnum.XX;
    }

    @Override
    public NotifyResult handlerNotify(String urlSuffix, JSONObject param) {
        if ("order".equals(urlSuffix)) {
            // todo 订单回调业务处理
            log.info("开始处理订单回调业务");
        }else if ("repay".equals(urlSuffix)) {
            //todo 还款业务回调处理
            log.info("开始处理还款回调业务");
        }

        return NotifyResult.builder()
                .thirdId(param.getString("loanId"))
                .thirdStatus(param.getIntValue("status"))
                .result(Result.success(param))
                .build();
    }

    @Override
    public List<String> registerNotifyUrl() {
        return Arrays.asList("order","repay");
    }

}
